public class SortColors {
    public static void code(int[] nums) {
        int n = nums.length;
        for (int i = 0, left = -1, right = n; i < right;){
            if (nums[i] == 0){
                swap(nums, ++left, i++);
            }else if (nums[i] == 1){
                i++;
            }else{
                swap(nums, --right, i);
            }
        }
    }

    public static void swap(int[] nums, int i, int j){
        int tmp = 0;
        tmp = nums[i];
        nums[i] = nums[j];
        nums[j] = tmp;
    }

    public static void main(String[] args) {
        SortColors.code(new int[]{2,0,2,1,1,0});
    }
}
